<template>
  <div>
    <div class="filter-container _formStyle_" style="padding: 10px 0">
      <el-form ref="form" :inline="true" :model="form">
        <el-form-item prop="flowName" label="流程名称：">
          <el-input v-model.trim="form.flowName" clearable />
        </el-form-item>
        <el-form-item>
          <el-form-item>
            <el-button
              class="filter-item"
              type="primary"
              icon="el-icon-search"
              @click="handleFilter"
              >查询</el-button
            >
            <el-button
              class="filter-item"
              style="margin-left: 10px"
              type="primary"
              icon="el-icon-edit-outline"
              @click="handleReset"
              >重置</el-button
            >
          </el-form-item>
        </el-form-item>
      </el-form>
    </div>
    <el-table height="680" :data="list" highlight-current-row>
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="id"
      />
      <el-table-column
        prop="flowName"
        header-align="center"
        align="center"
        label="流程名称"
      />
      <el-table-column
        prop="flowEnName"
        header-align="center"
        align="center"
        label="流程英文名"
      />
      <el-table-column
        prop="packageName"
        header-align="center"
        align="center"
        label="功能模块"
      />
      <el-table-column
        header-align="center"
        align="center"
        width="150"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleUpdate(scope.row)"
            >编辑</el-button
          >
          <!-- <el-button type="text" size="small" @click="deleteHandle(scope.row)">删除</el-button> -->
          <el-button
            type="text"
            size="small"
            @click="handleLogicUpdate(scope.row)"
            >编辑流程逻辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <scheduledFixedTasks
      :editDate="editDate"
      @close="handleClose"
      :scheduledFixedTasksVisible="scheduledFixedTasksVisible"
      v-if="scheduledFixedTasksVisible"
    />
  </div>
</template>

<script>
import { listScheduleFlow, jlcpCodeConfigDelete } from "@/api/lowcode";
import scheduledFixedTasks from "./scheduledFixedTasks.vue";
export default {
  name: "scheduledFixedTaskLists",
  components: { scheduledFixedTasks },
  inject: ["moduleModetTreeList"],
  data() {
    return {
      currentComponent: "customQuery",
      editDate: {},
      scheduledFixedTasksVisible: false,
      // 筛选框的 form 表单
      form: {
        projectId: +sessionStorage.getItem("developLowCodeId"),
        flowName: "",
      },
      list: [], // 表格数据
    };
  },
  async created() {
    this.getList();
  },
  methods: {
    async handleLogicUpdate(row) {
      this.$parent.$parent.$parent.currentComponent = "basicsssssComponents";
      await this.moduleModetTreeList();
      this.$parent.$parent.$parent.fengzhuangConent(row.id);
      this.$parent.$parent.$parent.treeGaoliangAndscroll(row.id);
    },
    handleClose() {
      this.scheduledFixedTasksVisible = false;
      this.getList();
    },
    // 获取表格数据
    async getList() {
      this.list = [];
      const res = await listScheduleFlow(this.form);
      if (res?.code === 200) {
        this.list = res.data;
      }
    },
    // 重新获取表格数据 页码归为1
    handleFilter() {
      // this.form.page = 1;
      this.getList();
    },
    handleReset() {
      this.form = {
        projectId: +sessionStorage.getItem("developLowCodeId"),
        flowName: "",
      };
      this.getList();
    },
    handleUpdate(row) {
      this.scheduledFixedTasksVisible = true;
      this.editDate = JSON.parse(JSON.stringify(row));
    },
    async deleteHandle(item) {
      this.$confirm(`确定要进行删除操作?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        const res = await jlcpCodeConfigDelete([item.id]);
        if (res?.code === 200) {
          this.$message({
            message: "删除成功",
            type: "success",
          });
          this.getList();
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "~@/styles/layout-table.scss";
$rowLength: 2;
@media all and (min-width: 1659px) {
  $rowLength: 2;
  @include calculation($rowLength: $rowLength);
}
@media all and (max-width: 1659px) {
  $rowLength: 3;
  @include calculation($rowLength: $rowLength);
}
._formStyle_ ::v-deep .el-form-item__label {
  text-align: left;
  margin-top: 4px;
}
</style>
